package com.bbx.demo.nio;

import lombok.extern.slf4j.Slf4j;

import java.nio.IntBuffer;

/**
 * buffer  必要属性验
 */
@Slf4j
public class BufferPropertiesTest {

    public static void main(String [] args){
        IntBuffer buffer = IntBuffer.allocate(10);
        //初始化完后   buffer 必要属性  capacity=10, limit =10 , and position= 0
        log.info("初始化---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        int i = 0;
        while (i <=4){
            buffer.put(i);
            i++;
        }
        log.info("写入数据后---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        buffer.flip();
        log.info("反转后---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        int i1 = buffer.get();
        log.info("读取后---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        buffer.flip();
        log.info("再次反转后---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        buffer.put(1);
        log.info("再次反转后--写入---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        buffer.limit(buffer.capacity());
        log.info(" newLimit---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        log.info("~~~~~~~~~~~~~~~~~~~~~~~~分割线，下面是Buffer 的其他方法~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        buffer.put(1);
        buffer.put(2);
        log.info("mark 标记前---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        buffer.mark();
        buffer.put(3);
        log.info("mark 标记前---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        buffer.reset();
        log.info("reset 后---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());
        buffer.rewind();
        log.info("rewind 后---capacity[{}],limit[{}],position[{}]", buffer.capacity(),buffer.limit(),buffer.position());







    }
}
